package com.iaz.tech.tools.property.impl;

import lombok.Data;
import lombok.EqualsAndHashCode;
 
import java.util.Date; 

import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 
import com.iaz.tech.tools.property.IPropertyAble;

/**
 * 数据属性，
 * 属性数据，存储基础数据值
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class ValueProperty extends Property {
    
	/**
     * 日志
     */
	private final static Logger logger = (Logger) LoggerFactory.getLogger(ValueProperty.class);
	
	/**
     * 数据缓冲
     * 字节流
     */
    private byte[] buffer;
    /**
     * Object 对象
     */
    private Object object;
    /**
     * 
     */
    private String dataTypeString;

    /**
     * 将值转换成数据
     * @return
     */
    public String toString() {
        try {
            if (this.object == null) {
                return "";
            }
            return object.toString();
        } catch(Exception e){
            logger.error("toString error: {}", e.getMessage());
        }
        return "";
    }

    /**
     * 转换成byte
     * @return
     */
    public byte toByte() {
        return 0;
    }

    public char toChar() {
        return 0;
    }

    public short toShort() {
        return 0;
    }

    public int toInt() {
        return 0;
    }

    public long toLong() {
        return 0L;
    }

    public float toFloat() {
        return 0.0f;
    }

    public double toDouble() {
        return 0.0d;
    }

    public Date toDate() {
        return new Date();
    }
    
    public boolean toBoolean() {
    	return false;
    }

    public Object toObject() {
        return null;
    }

	@Override
	public void push(Object _value) {
		try {
			if (_value == null) {
				throw new Exception("_value is null!");
			}
			
			this.object = _value;
			this.setPropDataType(_value.getClass());
		}catch(Exception e) {
			logger.error("异常：" + e.getMessage());
		}		
	}

	@Override
	public void push(IPropertyAble property) {
		try {
			if (property == null) {
				throw new Exception("_value is null!");
			}
			
			this.object = property;
			
		}catch(Exception e) {
			logger.error("异常：" + e.getMessage());
		}	
		
	}    
	
	@Override
    public void push(String path, Object _value) {
    	try {
    		if (_value == null) {
				throw new Exception("_value is null!");
			}
			
			this.object = _value;
			this.setName( path );
			this.setPropDataType(_value.getClass());
    	} catch(Exception e) {
    		logger.error("出现异常：" + e.getMessage());
    	}
    }

	@Override
	public void push(String path, IPropertyAble property) {
		try {
			if (property == null) {
				throw new Exception("_value is null!");
			}
			this.setName( path );
			this.object = property;
		} catch(Exception e) {
    		logger.error("出现异常：" + e.getMessage());
    	}
	}
	
	/**
     * 填充
     * @param path
     * @param key
     * @param _value
     */
    public void push(String path, String key,  Object _value) {
    	try {
			if (_value == null) {
				throw new Exception("_value is null!");
			}
		
			this.object = _value;
			this.setPropDataType(_value.getClass());
			this.setName( key );
		} catch(Exception e) {
			logger.error("出现异常：" + e.getMessage());
		}
    }
    /**
     * 填充对象Property
     * @param path
     * @param key
     * @param property
     */
    public void push(String path, String key, IPropertyAble property) {
    	try {
			if (property == null) {
				throw new Exception("_value is null!");
			}
			
			this.object = property;
			this.setName( key );
		} catch(Exception e) {
    		logger.error("出现异常：" + e.getMessage());
    	}
    }
}
